import { Meta, ArgsTable, Canvas, Story, Markdown } from '@storybook/addon-docs';
import { useArgs } from '@storybook/client-api';
import { Textarea } from '@zendeskgarden/react-forms';
import { TextareaStory } from './stories/TextareaStory';
import { commonArgs, commonArgTypes, fieldSubcomponents } from './stories/common';
import README from '../README.md';

<Meta
  title="Packages/Forms/Textarea"
  component={Textarea}
  subcomponents={{ ...fieldSubcomponents }}
  args={{
    ...commonArgs
  }}
  argTypes={{
    /* ensures the `validation` story arg for the `Textarea` component is not overriden */
    ...{ ...commonArgTypes, validation: {} },
    disabled: { control: 'boolean' },
    readOnly: { control: 'boolean' },
    placeholder: { control: 'text' }
  }}
  parameters={{
    design: {
      allowFullscreen: true,
      type: 'figma',
      url: 'https://www.figma.com/file/6g87L4FdKZTA3knt3Rsfdx/Garden?node-id=103%3A20266'
    }
  }}
/>

# API

<ArgsTable />

# Demo

## Uncontrolled

<Canvas>
  <Story name="Uncontrolled" args={{ placeholder: 'Placeholder' }}>
    {args => <TextareaStory {...args} />}
  </Story>
</Canvas>

## Controlled

<Canvas>
  <Story name="Controlled" args={{ value: 'Value' }}>
    {args => {
      const updateArgs = useArgs()[1];
      const handleChange = event => updateArgs({ value: event.target.value });
      return <TextareaStory {...args} onChange={handleChange} />;
    }}
  </Story>
</Canvas>

<Markdown>{README}</Markdown>
